package com.jetpackframework.room;

import android.content.Context;

import androidx.sqlite.db.SupportSQLiteDatabase;
import androidx.sqlite.db.SupportSQLiteOpenHelper;


public class Helper implements SupportSQLiteOpenHelper {
    private final String name;
    private final byte[] passphrase;
    private OpenHelper sqLiteOpenHelper;

    public Helper(Context context, String name, Callback callback, byte[] passphrase) {
        this.name = name;
        this.passphrase = passphrase;
        sqLiteOpenHelper = new OpenHelper(context,name,callback,new SqliteDatabase[1]);
    }

    @Override
    public String getDatabaseName() {
        return name;
    }

    @Override
    public void setWriteAheadLoggingEnabled(boolean enabled) {
        sqLiteOpenHelper.setWriteAheadLoggingEnabled(enabled);
    }

    @Override
    public SupportSQLiteDatabase getWritableDatabase() {
        SupportSQLiteDatabase database = sqLiteOpenHelper.getDB(passphrase);
        return database;
    }

    @Override
    public SupportSQLiteDatabase getReadableDatabase() {
        return getWritableDatabase();
    }

    @Override
    public void close() {
        sqLiteOpenHelper.close();
    }
}
